﻿namespace PillBox.Client.Views
{
    using System.Windows.Controls;
    using PillBox.Client.Framework;
    using System;

    public partial class PeopleView : UserControl, IView
    {
        private Action _completedAction;

        public PeopleView()
        {
            InitializeComponent();

            this.Loaded += PeopleView_Loaded;
        }

        public void DeActivate(Action completed)
        {
            this._completedAction = completed;

            this.PageTransitionList.Completed += PageTransitionList_Completed;
            this.PageTransitionList.Begin();
        }

        private void PeopleView_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            this.ResetPageTransitionList.Begin();
        }

        private void PageTransitionList_Completed(object sender, EventArgs e)
        {
            this.PageTransitionList.Completed -= PageTransitionList_Completed;

            if (this._completedAction != null)
            {
                this._completedAction();
                this._completedAction = null;
            }
        }
    }
}